﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CircleGuide : GuideBase, ICanvasRaycastFilter
{
    public override GuideType guideType => GuideType.Circle;

    private float r; // 镂空区域圆形的半径
    public override void Guide(RectTransform target)
    {
        base.Guide(target);
        float width = (targetCorners[3].x - targetCorners[0].x) / 2;
        float height = (targetCorners[1].y - targetCorners[0].y) / 2;
        //计算半径,宽/2的平方 + 高/2的平方，之后开方
        r = Mathf.Sqrt(width * width + height * height);
        // 赋值给材质
        material.SetFloat("_Slider", r);
    }

    public bool IsRaycastLocationValid(Vector2 sp, Camera eventCamera)
    {
        Vector2 selfPos = RectTransformUtility.WorldToScreenPoint(eventCamera, transform.position);
        return !((selfPos - sp).sqrMagnitude <= r * r);
    }
}